package com.asset.dispoal.commpany;

import com.asset.dispoal.company.api.CompanyQueryService;
import com.asset.dispoal.company.api.CompanyService;
import com.asset.dispoal.company.dto.CompanyAreaStatisticsRequest;
import com.asset.dispoal.company.dto.CompanyAreaStatisticsResponse;
import com.asset.dispoal.company.dto.CompanyCourtAreaInsert;
import com.asset.dispoal.company.dto.CompanyLawFirmCourtInsert;
import com.asset.dispoal.company.dto.CompanyRequest;
import com.asset.dispoal.company.dto.CompanyResponse;
import com.asset.dispoal.company.dto.CompanySelectResponse;
import com.asset.dispoal.company.dto.CompanySelected;
import com.asset.dispoal.company.dto.PlaintiffCourtRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @author qr
 * @date 2022/1/25$
 */
@RestController
@Api(value = "公司管理", tags = "公司管理")
@RequestMapping("sys/company")
public class CompanyController {

    @Autowired
    CompanyService companyService;

    @Autowired
    CompanyQueryService companyQueryService;


    @Deprecated
    @GetMapping("queryPage")
    public Result<PageVO<CompanyResponse>> queryPage(CompanyRequest companyRequest) {
        return companyQueryService.queryPage(companyRequest);
    }

    @Deprecated
    @PostMapping("insert")
    public Result insert(@RequestBody CompanyRequest companyRequest) {
        companyService.insert(companyRequest);
        return Result.ok();
    }

    @Deprecated
    @PostMapping("update")
    public Result update(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Deprecated
    @PostMapping("delete")
    public Result delete(@RequestBody String id) {
        companyService.delete(id);
        return Result.ok();
    }

    @Permission(code = "companyDebtbsnk:query", param = "create_user")
    @GetMapping("companyDebtbankPage")
    @ApiOperation(value = "债行管理查询接口", notes = "债行管理查询接口")
    public Result<PageVO<CompanyResponse>> companyDebtbank(CompanyRequest companyRequest) {
        return companyQueryService.queryPage(companyRequest);
    }


    @Permission(code = "companyDebtbsnk:add")
    @PostMapping("companyDebtbsnkInsert")
    @ApiOperation(value = "债行管理新增接口", notes = "债行管理新增接口")
    public Result companyDebtbsnkInsert(@RequestBody CompanyRequest companyRequest) {
        companyService.insert(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyDebtbsnk:update")
    @PostMapping("companyDebtbsnkUpdate")
    @ApiOperation(value = "债行管理修改接口", notes = "债行管理修改接口")
    public Result companyDebtbsnkUpdate(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyDebtbsnk:del")
    @PostMapping("companyDebtbsnkDelete")
    @ApiOperation(value = "债行管理删除接口", notes = "债行管理删除接口")
    public Result companyDebtbsnkDelete(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyLawfirm:query", param = "create_user")
    @GetMapping("companyLawfirmPage")
    @ApiOperation(value = "律所管理查询接口", notes = "律所管理查询接口")
    public Result<PageVO<CompanyResponse>> companyLawfirm(CompanyRequest companyRequest) {
        return companyQueryService.queryPage(companyRequest);
    }

    @Permission(code = "companyLawfirm:add")
    @PostMapping("companyLawfirmInsert")
    @ApiOperation(value = "律所管理新增接口", notes = "律所管理新增接口")
    public Result companyLawfirmInsert(@RequestBody CompanyRequest companyRequest) {
        companyService.insert(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyLawfirm:update")
    @PostMapping("companyLawfirmUpdate")
    @ApiOperation(value = "律所管理修改接口", notes = "律所管理修改接口")
    public Result companyLawfirmUpdate(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyLawfirm:del")
    @PostMapping("companyLawfirmDelete")
    @ApiOperation(value = "律所管理删除接口", notes = "律所管理删除接口")
    public Result companyLawfirmDelete(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyPartners:query", param = "create_user")
    @GetMapping("findTree")
    @ApiOperation(value = "合作机构查询接口", notes = "合作机构查询接口")
    public Result<List<CompanyResponse>> findTree(CompanyRequest companyRequest) {
        return companyQueryService.findTree(companyRequest);
    }

    @Permission(code = "companyPartners:add")
    @PostMapping("companyPartnersInsert")
    @ApiOperation(value = "合作机构新增接口", notes = "合作机构新增接口")
    public Result companyPartnersInsert(@RequestBody CompanyRequest companyRequest) {
        companyService.insert(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyPartners:update")
    @PostMapping("companyPartnersUpdate")
    @ApiOperation(value = "合作机构修改接口", notes = "合作机构修改接口")
    public Result companyPartnersUpdate(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyPartners:del")
    @PostMapping("companyPartnersDelete")
    @ApiOperation(value = "合作机构删除接口", notes = "合作机构删除接口")
    public Result companyPartnersDelete(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @GetMapping("queryLawFirmSelectedCourt")
    @ApiOperation(value = "查询律所法院绑定接口", notes = "查询律所法院绑定接口")
    public Result<List<CompanySelected>> queryLawFirmSelectedCourt(String lawFirmId) {
        return companyQueryService.queryLawFirmSelectedCourt(lawFirmId);
    }

    @GetMapping("queryCourtSelectedCourt")
    @ApiOperation(value = "查询法院区域绑定接口", notes = "查询法院区域绑定接口")
    public Result<List<CompanySelected>> queryCourtSelectedCourt(String courtId) {
        return companyQueryService.queryCourtSelectedCourt(courtId);
    }

    @PostMapping("insertLawFirmCourt")
    @ApiOperation(value = "律所法院绑定接口", notes = "律所法院绑定接口")
    public Result insertLawFirmCourt(@RequestBody CompanyLawFirmCourtInsert companyLawFirmCourtInsert) {
        return companyService.insertLawFirmCourt(companyLawFirmCourtInsert);
    }

    @PostMapping("insertCourtArea")
    @ApiOperation(value = "法院区域绑定接口", notes = "法院区域绑定接口")
    public Result insertCourtArea(@RequestBody CompanyCourtAreaInsert companyCourtAreaInsert) {
        return companyService.insertCourtArea(companyCourtAreaInsert);
    }

    @Permission(code = "companyCourt:query", param = "create_user")
    @GetMapping("companyCourtPage")
    @ApiOperation(value = "法院管理查询接口", notes = "法院管理查询接口")
    public Result<PageVO<CompanyResponse>> companyCourt(CompanyRequest companyRequest) {
        return companyQueryService.queryPage(companyRequest);
    }

    @GetMapping("companyCourtList")
    @ApiOperation(value = "法院管理查询接口", notes = "法院管理查询接口")
    public Result<List<CompanyResponse>> companyCourtList() {
        return companyQueryService.companyCourtList();
    }

    @Permission(code = "companyCourt:add")
    @PostMapping("companyCourtInsert")
    @ApiOperation(value = "法院管理新增接口", notes = "法院管理新增接口")
    public Result companyCourtInsert(@RequestBody CompanyRequest companyRequest) {
        companyService.insert(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyCourt:update")
    @PostMapping("companyCourtUpdate")
    @ApiOperation(value = "法院管理修改接口", notes = "法院管理改接口")
    public Result companyCourtUpdate(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @Permission(code = "companyCourt:del")
    @PostMapping("companyCourtDelete")
    @ApiOperation(value = "法院管理删除接口", notes = "法院管理删除接口")
    public Result companyCourtDelete(@RequestBody CompanyRequest companyRequest) {
        companyService.update(companyRequest);
        return Result.ok();
    }

    @GetMapping("/queryCourtByPlaintiffId")
    public Result<List<CompanySelectResponse>> queryCourtByPlaintiffId(PlaintiffCourtRequest request) {
        return companyQueryService.queryCourtByPlaintiffId(request);
    }

    @GetMapping("queryStaitstics")
    public Result<List<CompanyAreaStatisticsResponse>> queryStatistics(CompanyAreaStatisticsRequest request) {
        return companyQueryService.queryStatistics(request);
    }
}
